package org.budo.phone.api;

import org.budo.phone.api.BudoPhoneEvent.Type;

import lombok.extern.slf4j.Slf4j;

/**
 * 基类，业务代码可以选择实现部分方法
 * 
 * @author limingwei
 */
@Slf4j
public class AbstractPhoneEventListener implements BudoPhoneEventListener {
    /**
     * 根据事件类型不同，分发到不同的处理方法，如果覆盖这个方法，请留意
     */
    @Override
    public Object onEvent(BudoPhoneEvent event) {
        if (null == event || null == event.getType()) {
            log.error("#20 event is null, event=" + event);
            return null;
        }

        if (Type.CallAuth.equals(event.getType())) {
            return this.onCallAuth(event);
        }

        if (Type.CallEstablish.equals(event.getType())) {
            return this.onCallEstablish(event);
        }

        if (Type.Hangup.equals(event.getType())) {
            return this.onHangup(event);
        }

        if (Type.CallIn.equals(event.getType())) {
            return this.onCallIn(event);
        }

        log.info("#29 onEvent, event=" + event);
        return null;
    }

    /**
     * 呼入建立前回调,返回队列信息
     */
    public Object onCallIn(BudoPhoneEvent event) {
        log.info("#45 onCallIn, event=" + event);
        return null;
    }

    /**
     * 外呼建立前回调,返回外呼号
     */
    public Object onCallAuth(BudoPhoneEvent event) {
        log.info("#36 onHangup, event=" + event);
        return null;
    }

    /**
     * 挂机事件
     */
    public Object onHangup(BudoPhoneEvent event) {
        log.info("#41 onHangup, event=" + event);
        return null;
    }

    /**
     * 呼叫建立事件
     */
    public Object onCallEstablish(BudoPhoneEvent event) {
        log.info("#46 onCallEstablish, event=" + event);
        return null;
    }
}